let form=document.querySelector('form');
let nameInp=document.querySelector('.username');
let ageInp=document.querySelector('.age')
let genderSel=document.querySelector('.gender');
let nickInp=document.querySelector('.nickname');
async function fn() {
    let {status,info,id}=await isLogin();
    if(status =!1){
        location.href='../views/login.html';
        return;
    }

    nameInp.value=info.username;
    ageInp.value=info.age;
    nickInp.value=info.nickname;
    genderSel.value=info.gender;

    form.addEventListener('submit',async e=>{
        e.preventDefault();

        let data={id};

        if(ageInp.value) data.age=ageInp.value;
        if(genderSel.value) data.gender=genderSel.value;
        if(nickInp.value) data.nickname=nickInp.value;

        let r=await http.post('/users/update',data)

        // let r=http.post('/users/update',data);
        if(r.data.code !=1) return alert('修改失败，请重试!!');
        alert('修改成功');
    })
}
fn();
